var express = require('express');
var router = express.Router();
var sql = require('./../sql');
var Banner = require('./../sql/col/banners')
/**
 * @api {get} api/banner 获取轮播图的数据
 * @apiDescription 获取轮播图的数据
 * @apiName banner
 * @apiGroup banner
 * @apiSuccessExample { json } Success-Response:
 * {
 *  code: '200',
 *  message: '获取轮播图的数据',
 *  data: []
 * }
 * @apiSampleRequest /api/banner
 * @apiVersion 1.0.0
 */
router.get('/', function (req, res, next) {
  sql.find(Banner, {}, { _id: 0 }).then(data => {
    res.send({
      code: '200',
      message: '获取轮播图的数据',
      data: data
    });
  })
});



router.get('/upload', (req, res, next) => {
  let arr = [
    {
      "bannerid": "banner_1",
      "img": "https://gw.alicdn.com/tfs/tfs/TB1.Zy6OFXXXXbhXpXXXXXXXXXX-1280-520.jpg",
      "href": "",
      "alt": ""
    },
    {
      "bannerid": "banner_2",
      "img": "https://gw.alicdn.com/tfs/tps/TB1YTkBOpXXXXbLaXXXXXXXXXXX-1280-520.jpg",
      "href": "",
      "alt": ""
    },
    {
      "bannerid": "banner_3",
      "img": "https://gw.alicdn.com/tfs/tps/TB1TikAOpXXXXaWXFXXXXXXXXXX-1280-520.jpg",
      "href": "",
      "alt": ""
    },
    {
      "bannerid": "banner_4",
      "img": "https://gw.alicdn.com/tfs/tps/TB1TikAOpXXXXaWXFXXXXXXXXXX-1280-520.jpg",
      "href": "",
      "alt": ""
    },
    {
      "bannerid": "banner_5",
      "img": "https://gw.alicdn.com/tfs/tps/TB1TikAOpXXXXaWXFXXXXXXXXXX-1280-520.jpg",
      "href": "",
      "alt": ""
    }
  ]
  // res.send(arr)
  sql.insert(Banner, arr).then(() => {
    res.send('插入成功')
  })
})
  module.exports = router;
